#include <stdio.h>
#include <stdlib.h>
#include "test_linkedlist.h"
#include "../../include/type_list.h"
#include "../../src/common/func.h"
#include "../../src/linked_list/linked_list.h"
#include "../../src/linked_list/create_linked_list.h"
#include "../../src/linked_list/merge_linked_list.h"

void testCreateList(){
    LinkList L1; 
    CreateList_L(L1,3);
    ListPrint_L(L1);
}

void  testMergeLinkedList(){
    LinkList L1; 
    CreateList_L(L1,3);
    printf("---- print L1 -----");
    ListPrint_L(L1);

    LinkList L2;
    CreateList_L(L2,5);
    printf("---- print L2 -----");
    ListPrint_L(L2);

    LinkList L3;
    Mergelist_L(L1,L2,L3);
    printf("---- print L3 -----");
    ListPrint_L(L3);

    free_L(L3);
}

void testLinkedList(){

    LNode * nodeHead = (LNode * ) malloc (sizeof (LNode));                     //头结点
    LNode * node1 = (LNode * ) malloc (sizeof (LNode));
    LNode * node2 = (LNode * ) malloc (sizeof (LNode));
    LNode * node3 = (LNode * ) malloc (sizeof (LNode));
    LNode * node4 = (LNode * ) malloc (sizeof (LNode));

    nodeHead -> data = 0;
    nodeHead -> next = node1;
    node1 -> data = 1;
    node1 -> next = node2;
    node2 -> data = 2;
    node2 -> next = node3;
    node3 -> data = 3;
    node3 -> next = node4;
    node4 -> data = 4;
    //node4.next = 0;

    LinkList L = nodeHead;
    ListPrint_L(L);                          //1,2,3,4

    printf("----- insert pre ---- \n");
    ElemType insertData = 55;
    ListInsert_L(L,2,insertData);       
    ListPrint_L(L);                          //1,55,2,3,4
    printf("----- insert back ---- \n");

    //L 是 1,55,2,3,4 但是打印忽略了头结点，头结点去哪了？
    printf("----- delete pre ---- \n");
    ElemType deleteData = 0;
    ListDelete_L(L,3,deleteData);            //1,55,3,4
    ListPrint_L(L); 
    printf("----- delete back ---- \n");

    free_L(L);
}
